<template>
	<view class="wrap">
		<view class="table_item" v-for="item in data">
			<view class="item">
				<view class="label">SlimSubJobNo</view>
				<view class="info">{{item.slimSubJobNo}}</view>
			</view>
			<view class="item">
				<view class="label">OrderNo</view>
				<view class="info">{{item.orderNo}}</view>
			</view>
			<view class="item">
				<view class="label">OrderId</view>
				<view class="info">{{item.orderId}}</view>
			</view>
			<view class="item">
				<view class="label">报告</view>
				<view class="info">{{item.cloudId}}</view>
			</view>
			<view class="item">
				<view class="label">创建时间</view>
				<view class="info">{{item.createTime}}</view>
			</view>
			<view class="item">
				<view class="btn" @tap="downfile(item)">报告下载</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {toast} from '@/common/public.js'
	import {mixins} from '@/common/mixins.js'
	export default {
		mixins:[mixins],
		data() {
			return {
				data:[],
				param: {
					current:1,
					size:10,
					trfId:'',
					weUserId:''
				},
				pages:0,
				entry:2
			}
		},
		onLoad(options) {
			this.param.trfId = options.trfId || '867d324cfc47269f1114b906cc190a2f'
			uni.setStorageSync('sgs_userId','oovO-5xBKxK7ozWIQMkVgJ7oQOPI')
			// this.param.trfId = options.trfId || ''
			if(uni.getStorageSync('sgs_userId')) {
				this.initData()
			} else {
				this.wxAuth()
			}
		},
		methods: {
			initData() {
				this.param.weUserId = uni.getStorageSync('sgs_userId')
				uni.showLoading({
					title:'加载中...'
				})
				this.pageForWechat()
			},
			pageForWechat() {
				this.$api.pageForWechat(this.param).then(res=>{
					uni.hideLoading()
					if (res.code == 200) {
						if (this.param.current==1) {
							this.data = []
							this.pages = res.data.pages
						}
						let list = res.data.records
						this.data = this.data.concat.apply(this.data,list)
					} else {
						toast(res.msg)
					}
				})
			},
			downfile(item) {
				uni.showLoading({
					title:'下载中...'
				})
				let param = {
					systemID:1,
					networkType:2,
					hash:new Date().getTime(),
					cloudID:item.cloudId
				}
				this.$api.downloadByCloudID(param).then(res=>{
					if (res) {
						let link = res.replace(/\s*/g,'')
						let fileUrl = encodeURIComponent(link)
						let fileName = item.fileName
						let url = this.baseUrl+'/api/sgs-mart/afl/trf/fileDownload?fileUrl='+fileUrl+'&fileUrlName='+fileName
						window.top.location.href=window.location.origin+window.location.pathname+"/hybrid/html/download.html?fileurl="+encodeURIComponent(url);
						// uni.downloadFile({
						//     url: url, //仅为示例，并非真实的资源
						//     success: (res) => {
						// 			if (res.statusCode === 200) {
						// 				uni.hideLoading()
						// 				uni.showToast({
						// 					title:'下载成功'
						// 				})
						// 			}
						//     },
						// 	fail:()=>{
						// 		uni.hideLoading()
						// 	}
						// });
					} else {
						uni.hideLoading()
						toast(res.msg)
					}
				})
			}
		},
		onReachBottom() {
			if (this.param.current < this.pages) {
				this.param.current++
				this.pageForWechat()
			}
		}
	}
</script>

<style scoped>
.wrap{
	padding:10rpx 10rpx 120rpx;
}
.table_item{
	margin-bottom: 40rpx;
	background-color: #fbfbfb;
}
.item{
	display: flex;
	border:2rpx solid #eee;
	margin-top: -2rpx;
	font-size: 26rpx;
}
.label{
	width: 180rpx;
	padding:10rpx;
	color:#333;
}
.info{
	flex:1;
	min-width: 0;
	padding:10rpx;
	word-wrap: break-word;
	border-left: 2rpx solid #eee;
	color:#444;
}
.btn{
	width: 160rpx;
	height: 50rpx;
	text-align: center;
	line-height: 50rpx;
	margin: 10rpx 0 10rpx 10rpx;
	color: #fff;
	font-size: 24rpx;
	background-color: #ff6600;
}
</style>
